package com.yugong.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yugong.common.Const;
import com.yugong.entity.dto.*;
import com.yugong.entity.vo.request.OrderClassRequestVO;
import com.yugong.entity.vo.response.OrderClassListResponseVO;
import com.yugong.mapper.*;
import com.yugong.service.OrderClassService;
import com.yugong.util.TimeUtils;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 订单班业务逻辑实现类
 *
 * @author yugong
 * @date 2024/2/18
 */
@Service
public class OrderClassServiceImpl extends ServiceImpl<OrderClassMapper, OrderClass> implements OrderClassService {
    @Resource
    private OrderClassMapper orderClassMapper;
    @Resource
    private MajorMapper majorMapper;
    @Resource
    private StudentMapper studentMapper;
    @Resource
    private OrderClassAdminMapper orderClassAdminMapper;
    @Resource
    private BusinessMapper businessMapper;
    @Resource
    private RoomMapper roomMapper;
    @Resource
    private CourseArrangeMapper courseArrangeMapper;
    @Resource
    private CourseScoreMapper courseScoreMapper;
    @Resource
    private TimeUtils timeUtils;

    /**
     * 根据班名、订单班管理员工号查询订单班信息
     *
     * @param pageNum           当前页
     * @param pageSize          当前页数据个数
     * @param orderClassAdminNo 订单班管理员工号
     * @param orderClassName    班名
     * @return 订单班信息
     */
    @Override
    public PageInfo<OrderClassListResponseVO> findOrderClassNoReleasePage(Integer pageNum, Integer pageSize, String orderClassAdminNo, String orderClassName) {
        PageHelper.startPage(pageNum, pageSize);
        LambdaQueryWrapper<OrderClass> orderClassLambdaQueryWrapper = new LambdaQueryWrapper<>();
        orderClassLambdaQueryWrapper
                .eq(OrderClass::getOrderClassAdministratorNo, orderClassAdminNo)
                .eq(OrderClass::getOrderClassState, 0)
                .like(OrderClass::getOrderClassName, orderClassName)
                .orderByDesc(OrderClass::getOrderClassCreateTime);
        List<OrderClass> orderClassList = orderClassMapper.selectList(orderClassLambdaQueryWrapper);
        List<OrderClassListResponseVO> orderClassListResponseVOList = new ArrayList<>();
        QueryWrapper<OrderClass> orderClassQueryWrapper = new QueryWrapper<>();
        orderClassQueryWrapper
                .eq("order_class_administrator_no", orderClassAdminNo)
                .eq("order_class_state", 0)
                .like("order_class_name", orderClassName);
        Long orderClassCountNumber = orderClassMapper.selectCount(orderClassQueryWrapper);
        for (OrderClass orderClass : orderClassList) {
            OrderClassListResponseVO orderClassListResponseVO = new OrderClassListResponseVO();
            orderClassListResponseVO.setOrderClassNo(orderClass.getOrderClassNo());
            orderClassListResponseVO.setOrderClassName(orderClass.getOrderClassName());
            orderClassListResponseVO.setOrderClassIntroduction(orderClass.getOrderClassIntroduction());
            orderClassListResponseVO.setOrderClassState(orderClass.getOrderClassState());
            orderClassListResponseVO.setOrderClassStateName("未发布");
            orderClassListResponseVO.setOrderClassRealityNumber(orderClass.getOrderClassRealityNumber());
            String startTime = timeUtils.setDateToStrDate(orderClass.getOrderClassStartTime(), Const.YYYY_MM_DD);
            orderClassListResponseVO.setOrderClassStartTime(startTime);
            String EndTime = timeUtils.setDateToStrDate(orderClass.getOrderClassEndTime(), Const.YYYY_MM_DD);
            orderClassListResponseVO.setOrderClassEndTime(EndTime);
            orderClassListResponseVO.setOrderClassAdministratorNo(orderClassAdminNo);
            OrderClassAdmin orderClassAdmin = orderClassAdminMapper.selectById(orderClassAdminNo);
            if (orderClassAdmin == null) {
                orderClassListResponseVO.setOrderClassAdministratorName("未填写");
            } else {
                orderClassListResponseVO.setOrderClassAdministratorName(orderClassAdmin.getOrderClassAdminName());
            }
            orderClassListResponseVO.setOrderClassBusinessNo(orderClass.getOrderClassBusinessNo());
            Business business = businessMapper.selectById(orderClass.getOrderClassBusinessNo());
            if (business == null) {
                orderClassListResponseVO.setOrderClassBusinessName("未填写");
                orderClassListResponseVO.setOrderClassBusinessOrderClassHeadName("未填写");
            } else {
                orderClassListResponseVO.setOrderClassBusinessName(business.getBusinessName());
                orderClassListResponseVO.setOrderClassBusinessOrderClassHeadName(business.getBusinessOrderClassHeadName());
                orderClassListResponseVO.setOrderClassBusinessRoomNo(business.getBusinessRoomNo());
                Room room = roomMapper.selectById(business.getBusinessRoomNo());
                if (room == null) {
                    orderClassListResponseVO.setOrderClassBusinessRoomNo("未填写");
                    orderClassListResponseVO.setOrderClassBusinessRoomName("未填写");
                } else {
                    orderClassListResponseVO.setOrderClassBusinessRoomNo(room.getRoomNo());
                    orderClassListResponseVO.setOrderClassBusinessRoomName(room.getRoomName());
                }
            }
            orderClassListResponseVO.setOrderClassMajorNo(orderClass.getOrderClassMajorNo());
            Major major = majorMapper.selectById(orderClass.getOrderClassMajorNo());
            if (major == null) {
                orderClassListResponseVO.setOrderClassMajorName("未填写");
            } else {
                orderClassListResponseVO.setOrderClassMajorName(major.getMajorName());
            }
            orderClassListResponseVO.setOrderClassCreateMan(orderClass.getOrderClassCreateMan());
            String createTime = timeUtils.setDateToStrDate(orderClass.getOrderClassCreateTime(), Const.YYYY_MM_DD);
            orderClassListResponseVO.setOrderClassCreateTime(createTime);
            if (orderClass.getOrderClassCreateMan() == null) {
                orderClassListResponseVO.setOrderClassUpdateMan("未更新");
            } else {
                orderClassListResponseVO.setOrderClassUpdateMan(orderClass.getOrderClassCreateMan());
            }
            if (orderClass.getOrderClassUpdateTime() == null) {
                orderClassListResponseVO.setOrderClassUpdateTime(null);
            } else {
                String updateTime = timeUtils.setDateToStrDate(orderClass.getOrderClassUpdateTime(), Const.YYYY_MM_DD);
                orderClassListResponseVO.setOrderClassUpdateTime(updateTime);
            }
            orderClassListResponseVO.setOrderClassCountNumber(orderClassCountNumber);
            orderClassListResponseVOList.add(orderClassListResponseVO);
        }
        return PageInfo.of(orderClassListResponseVOList);
    }

    /**
     * 新增订单班
     *
     * @param orderClassRequestVO 订单班请求实体类
     * @return 数据库影响行数
     */
    @Override
    public int addOrderClass(OrderClassRequestVO orderClassRequestVO) {
        OrderClass orderClass = new OrderClass();
        orderClass.setOrderClassNo(orderClassRequestVO.getOrderClassNo());
        orderClass.setOrderClassName(orderClassRequestVO.getOrderClassName());
        orderClass.setOrderClassIntroduction(orderClassRequestVO.getOrderClassIntroduction());
        orderClass.setOrderClassState(0);
        orderClass.setOrderClassRealityNumber(0);
        orderClass.setOrderClassStartTime(orderClassRequestVO.getOrderClassStartTime());
        orderClass.setOrderClassEndTime(orderClassRequestVO.getOrderClassEndTime());
        orderClass.setOrderClassAdministratorNo(orderClassRequestVO.getOrderClassAdministratorNo());
        orderClass.setOrderClassBusinessNo(orderClassRequestVO.getOrderClassBusinessNo());
        orderClass.setOrderClassMajorNo(orderClassRequestVO.getOrderClassMajorNo());
        orderClass.setOrderClassCreateMan(orderClassRequestVO.getOrderClassCreateMan());
        orderClass.setOrderClassCreateTime(new Date());
        return orderClassMapper.insert(orderClass);
    }

    /**
     * 修改订单班
     *
     * @param orderClassRequestVO 订单班请求实体类
     * @return 数据库影响行数
     */
    @Override
    public int updateOrderClass(OrderClassRequestVO orderClassRequestVO) {
        OrderClass orderClass = new OrderClass();
        orderClass.setOrderClassNo(orderClassRequestVO.getOrderClassNo());
        orderClass.setOrderClassName(orderClassRequestVO.getOrderClassName());
        orderClass.setOrderClassIntroduction(orderClassRequestVO.getOrderClassIntroduction());
        orderClass.setOrderClassStartTime(orderClassRequestVO.getStartTime());
        orderClass.setOrderClassEndTime(orderClassRequestVO.getEndTime());
        orderClass.setOrderClassAdministratorNo(orderClassRequestVO.getOrderClassAdministratorNo());
        orderClass.setOrderClassBusinessNo(orderClassRequestVO.getOrderClassBusinessNo());
        orderClass.setOrderClassMajorNo(orderClassRequestVO.getOrderClassMajorNo());
        orderClass.setOrderClassUpdateMan(orderClassRequestVO.getOrderClassCreateMan());
        orderClass.setOrderClassUpdateTime(new Date());
        return orderClassMapper.updateById(orderClass);
    }

    /**
     * 删除订单班
     *
     * @param orderClassNo 订单班号
     * @return 数据库影响行数
     */
    @Override
    public int deleteOrderClass(String orderClassNo) {
        return orderClassMapper.deleteById(orderClassNo);
    }

    /**
     * 订单班 发布、开班、结班
     *
     * @param orderClassState   订单班状态
     * @param orderClassNo      班号
     * @param orderClassAdminNo 订单班管理员工号
     * @return 数据库影响行数
     */
    @Override
    public int changeOrderClassState(Integer orderClassState, String orderClassNo, String orderClassAdminNo) {
        int totalFlag = 0;
        Date time = new Date();
        OrderClass orderClass = new OrderClass();
        orderClass.setOrderClassNo(orderClassNo);
        orderClass.setOrderClassState(orderClassState);
        orderClass.setOrderClassUpdateMan(orderClassAdminNo);
        orderClass.setOrderClassUpdateTime(time);
        if (2 == orderClassState) {
            QueryWrapper<Student> studentQueryWrapper = new QueryWrapper<>();
            studentQueryWrapper
                    .eq("student_order_class_no", orderClassNo)
                    .eq("student_order_class_review_state", 3);
            Long studentNumber = studentMapper.selectCount(studentQueryWrapper);
            orderClass.setOrderClassRealityNumber(Math.toIntExact(studentNumber));
            LambdaQueryWrapper<CourseArrange> courseArrangeLambdaQueryWrapper = new LambdaQueryWrapper<>();
            courseArrangeLambdaQueryWrapper
                    .eq(CourseArrange::getCourseArrangeOrderClassNo, orderClassNo);
            List<CourseArrange> courseArrangeList = courseArrangeMapper.selectList(courseArrangeLambdaQueryWrapper);
            for (CourseArrange courseArrange : courseArrangeList) {
                LambdaQueryWrapper<Student> studentLambdaQueryWrapper = new LambdaQueryWrapper<>();
                studentLambdaQueryWrapper
                        .eq(Student::getStudentOrderClassNo, orderClassNo)
                        .eq(Student::getStudentOrderClassReviewState, 3);
                List<Student> studentList = studentMapper.selectList(studentLambdaQueryWrapper);
                for (Student student : studentList) {
                    CourseScore courseScore = new CourseScore();
                    courseScore.setCourseScoreOrderClassNo(courseArrange.getCourseArrangeOrderClassNo());
                    courseScore.setCourseScoreCourseNo(courseArrange.getCourseArrangeCourseNo());
                    courseScore.setCourseScoreStudentNo(student.getStudentNo());
                    courseScore.setCourseScoreCreateMan(orderClassAdminNo);
                    courseScore.setCourseScoreCreateTime(time);
                    int addCourseScoreFlag = courseScoreMapper.insert(courseScore);
                    totalFlag = totalFlag + addCourseScoreFlag;
                }
            }
        }
        int updateOrderClassFlag = orderClassMapper.updateById(orderClass);
        return updateOrderClassFlag + totalFlag;
    }

    /**
     * 根据订单班管理员工号查询订单班
     *
     * @param orderClassAdminNo 订单班管理员工号
     * @return 订单班
     */
    @Override
    public List<OrderClassListResponseVO> findOrderClass(String orderClassAdminNo) {
        LambdaQueryWrapper<OrderClass> orderClassLambdaQueryWrapper = new LambdaQueryWrapper<>();
        orderClassLambdaQueryWrapper
                .eq(OrderClass::getOrderClassAdministratorNo, orderClassAdminNo)
                .eq(OrderClass::getOrderClassState, 0);
        List<OrderClass> orderClassList = orderClassMapper.selectList(orderClassLambdaQueryWrapper);
        List<OrderClassListResponseVO> orderClassListResponseVOList = new ArrayList<>();
        for (OrderClass orderClass : orderClassList) {
            OrderClassListResponseVO orderClassListResponseVO = new OrderClassListResponseVO();
            orderClassListResponseVO.setOrderClassNo(orderClass.getOrderClassNo());
            orderClassListResponseVO.setOrderClassName(orderClass.getOrderClassName());
            orderClassListResponseVOList.add(orderClassListResponseVO);
        }
        return orderClassListResponseVOList;
    }

    /**
     * 根据班名查询订单班信息
     *
     * @param pageNum        当前页
     * @param pageSize       当前页数据个数
     * @param orderClassName 班名
     * @return 订单班信息
     */
    @Override
    public PageInfo<OrderClassListResponseVO> findOrderClass(Integer pageNum, Integer pageSize, String orderClassName) {
        PageHelper.startPage(pageNum, pageSize);
        LambdaQueryWrapper<OrderClass> orderClassLambdaQueryWrapper = new LambdaQueryWrapper<>();
        orderClassLambdaQueryWrapper
                .like(OrderClass::getOrderClassName, orderClassName)
                .orderByDesc(OrderClass::getOrderClassCreateTime);
        List<OrderClass> orderClassList = orderClassMapper.selectList(orderClassLambdaQueryWrapper);
        List<OrderClassListResponseVO> orderClassListResponseVOList = new ArrayList<>();
        QueryWrapper<OrderClass> orderClassQueryWrapper = new QueryWrapper<>();
        orderClassQueryWrapper.like("order_class_name", orderClassName);
        Long orderClassCountNumber = orderClassMapper.selectCount(orderClassQueryWrapper);
        for (OrderClass orderClass : orderClassList) {
            OrderClassListResponseVO orderClassListResponseVO = new OrderClassListResponseVO();
            orderClassListResponseVO.setOrderClassNo(orderClass.getOrderClassNo());
            orderClassListResponseVO.setOrderClassName(orderClass.getOrderClassName());
            if (0 == orderClass.getOrderClassState()) {
                orderClassListResponseVO.setOrderClassState(orderClass.getOrderClassState());
                orderClassListResponseVO.setOrderClassStateName("未发布");
            } else if (1 == orderClass.getOrderClassState()) {
                orderClassListResponseVO.setOrderClassState(orderClass.getOrderClassState());
                orderClassListResponseVO.setOrderClassStateName("未开班");
            } else if (2 == orderClass.getOrderClassState()) {
                orderClassListResponseVO.setOrderClassState(orderClass.getOrderClassState());
                orderClassListResponseVO.setOrderClassStateName("已开班");
            } else {
                orderClassListResponseVO.setOrderClassState(orderClass.getOrderClassState());
                orderClassListResponseVO.setOrderClassStateName("已结班");
            }
            OrderClassAdmin orderClassAdmin = orderClassAdminMapper.selectById(orderClass.getOrderClassAdministratorNo());
            if (orderClassAdmin == null) {
                orderClassListResponseVO.setOrderClassAdministratorName("未填写");
            } else {
                orderClassListResponseVO.setOrderClassAdministratorName(orderClassAdmin.getOrderClassAdminName());
            }
            Major major = majorMapper.selectById(orderClass.getOrderClassMajorNo());
            if (major == null) {
                orderClassListResponseVO.setOrderClassMajorName("未填写");
            } else {
                orderClassListResponseVO.setOrderClassMajorName(major.getMajorName());
            }
            orderClassListResponseVO.setOrderClassRealityNumber(orderClass.getOrderClassRealityNumber());
            String startTime = timeUtils.setDateToStrDate(orderClass.getOrderClassStartTime(), Const.YYYY_MM_DD);
            orderClassListResponseVO.setOrderClassStartTime(startTime);
            String endTime = timeUtils.setDateToStrDate(orderClass.getOrderClassEndTime(), Const.YYYY_MM_DD);
            orderClassListResponseVO.setOrderClassEndTime(endTime);
            String createTime = timeUtils.setDateToStrDate(orderClass.getOrderClassCreateTime(), Const.YYYY_MM_DD);
            orderClassListResponseVO.setOrderClassCreateTime(createTime);
            orderClassListResponseVO.setOrderClassCountNumber(orderClassCountNumber);
            orderClassListResponseVOList.add(orderClassListResponseVO);
        }
        return PageInfo.of(orderClassListResponseVOList);
    }

    /**
     * 根据班号查询订单班状态
     *
     * @param orderClassNo 班号
     * @return 订单班状态
     */
    @Override
    public Integer findOrderClassState(String orderClassNo) {
        OrderClass orderClass = orderClassMapper.selectById(orderClassNo);
        return orderClass.getOrderClassState();
    }

    /**
     * 查询学生可以报名的订单班
     *
     * @return 学生可以报名的订单班
     */
    @Override
    public PageInfo<OrderClassListResponseVO> searchOrderClassStudent(Integer pageNum, Integer pageSize, String orderClassName, String studentNo) {
        PageHelper.startPage(pageNum, pageSize);
        LambdaQueryWrapper<OrderClass> orderClassLambdaQueryWrapper = new LambdaQueryWrapper<>();
        orderClassLambdaQueryWrapper
                .eq(OrderClass::getOrderClassState, 1)
                .like(OrderClass::getOrderClassName, orderClassName)
                .orderByDesc(OrderClass::getOrderClassCreateTime);
        List<OrderClass> orderClassList = orderClassMapper.selectList(orderClassLambdaQueryWrapper);
        QueryWrapper<OrderClass> orderClassQueryWrapper = new QueryWrapper<>();
        orderClassQueryWrapper
                .eq("order_class_state", 1)
                .like("order_class_name", orderClassName);
        Long orderClassCountNumber = orderClassMapper.selectCount(orderClassQueryWrapper);
        Student student = studentMapper.selectById(studentNo);
        List<OrderClassListResponseVO> orderClassListResponseVOList = new ArrayList<>();
        for (OrderClass orderClass : orderClassList) {
            OrderClassListResponseVO orderClassListResponseVO = new OrderClassListResponseVO();
            orderClassListResponseVO.setOrderClassNo(orderClass.getOrderClassNo());
            orderClassListResponseVO.setOrderClassName(orderClass.getOrderClassName());
            orderClassListResponseVO.setOrderClassState(orderClass.getOrderClassState());
            orderClassListResponseVO.setOrderClassStateName("未开班");
            orderClassListResponseVO.setStudentState(student.getStudentOrderClassReviewState());
            orderClassListResponseVO.setOrderClassIntroduction(orderClass.getOrderClassIntroduction());
            OrderClassAdmin orderClassAdmin = orderClassAdminMapper.selectById(orderClass.getOrderClassAdministratorNo());
            if (orderClassAdmin == null) {
                orderClassListResponseVO.setOrderClassAdministratorNo("未填写");
                orderClassListResponseVO.setOrderClassAdministratorName("未填写");
            } else {
                orderClassListResponseVO.setOrderClassAdministratorNo(orderClassAdmin.getOrderClassAdminNo());
                orderClassListResponseVO.setOrderClassAdministratorName(orderClassAdmin.getOrderClassAdminName());
            }
            Business business = businessMapper.selectById(orderClass.getOrderClassBusinessNo());
            if (business == null) {
                orderClassListResponseVO.setOrderClassBusinessNo("未填写");
                orderClassListResponseVO.setOrderClassBusinessName("未填写");
            } else {
                orderClassListResponseVO.setOrderClassBusinessNo(business.getBusinessNo());
                orderClassListResponseVO.setOrderClassBusinessName(business.getBusinessName());
            }
            Major major = majorMapper.selectById(orderClass.getOrderClassMajorNo());
            if (major == null) {
                orderClassListResponseVO.setOrderClassMajorName("未填写");
            } else {
                orderClassListResponseVO.setOrderClassMajorName(major.getMajorName());
            }
            orderClassListResponseVO.setOrderClassRealityNumber(orderClass.getOrderClassRealityNumber());
            String startTime = timeUtils.setDateToStrDate(orderClass.getOrderClassStartTime(), Const.YYYY_MM_DD);
            orderClassListResponseVO.setOrderClassStartTime(startTime);
            String endTime = timeUtils.setDateToStrDate(orderClass.getOrderClassEndTime(), Const.YYYY_MM_DD);
            orderClassListResponseVO.setOrderClassEndTime(endTime);
            orderClassListResponseVO.setOrderClassCountNumber(orderClassCountNumber);
            orderClassListResponseVOList.add(orderClassListResponseVO);
        }
        return PageInfo.of(orderClassListResponseVOList);
    }

    /**
     * 查询未发布的订单班
     *
     * @param orderClassState   未发布的订单班
     * @param orderClassAdminNo 工号
     * @return 未发布的订单班
     */
    @Override
    public List<OrderClassListResponseVO> findOrderClass(String orderClassAdminNo, Integer orderClassState) {
        LambdaQueryWrapper<OrderClass> orderClassLambdaQueryWrapper = new LambdaQueryWrapper<>();
        orderClassLambdaQueryWrapper
                .eq(OrderClass::getOrderClassState, orderClassState)
                .eq(OrderClass::getOrderClassAdministratorNo, orderClassAdminNo);
        List<OrderClass> orderClassList = orderClassMapper.selectList(orderClassLambdaQueryWrapper);
        List<OrderClassListResponseVO> orderClassListResponseVOList = new ArrayList<>();
        for (OrderClass orderClass : orderClassList) {
            OrderClassListResponseVO orderClassListResponseVO = new OrderClassListResponseVO();
            orderClassListResponseVO.setOrderClassNo(orderClass.getOrderClassNo());
            orderClassListResponseVO.setOrderClassName(orderClass.getOrderClassName());
            orderClassListResponseVOList.add(orderClassListResponseVO);
        }
        return orderClassListResponseVOList;
    }

    /**
     * 根据班名、订单班管理员工号查询订单班信息（发布）
     *
     * @param pageNum           当前页
     * @param pageSize          当前页数据个数
     * @param orderClassAdminNo 订单班管理员工号
     * @param orderClassName    班名
     * @return 订单班信息
     */
    @Override
    public PageInfo<OrderClassListResponseVO> findOrderClassReleasePage(Integer pageNum, Integer pageSize, String orderClassAdminNo, String orderClassName) {
        PageHelper.startPage(pageNum, pageSize);
        LambdaQueryWrapper<OrderClass> orderClassLambdaQueryWrapper = new LambdaQueryWrapper<>();
        orderClassLambdaQueryWrapper
                .eq(OrderClass::getOrderClassAdministratorNo, orderClassAdminNo)
                .eq(OrderClass::getOrderClassState, 1)
                .like(OrderClass::getOrderClassName, orderClassName)
                .orderByDesc(OrderClass::getOrderClassCreateTime);
        List<OrderClass> orderClassList = orderClassMapper.selectList(orderClassLambdaQueryWrapper);
        List<OrderClassListResponseVO> orderClassListResponseVOList = new ArrayList<>();
        QueryWrapper<OrderClass> orderClassQueryWrapper = new QueryWrapper<>();
        orderClassQueryWrapper
                .eq("order_class_administrator_no", orderClassAdminNo)
                .eq("order_class_state", 1)
                .like("order_class_name", orderClassName);
        Long orderClassCountNumber = orderClassMapper.selectCount(orderClassQueryWrapper);
        for (OrderClass orderClass : orderClassList) {
            OrderClassListResponseVO orderClassListResponseVO = new OrderClassListResponseVO();
            orderClassListResponseVO.setOrderClassNo(orderClass.getOrderClassNo());
            orderClassListResponseVO.setOrderClassName(orderClass.getOrderClassName());
            orderClassListResponseVO.setOrderClassIntroduction(orderClass.getOrderClassIntroduction());
            orderClassListResponseVO.setOrderClassState(orderClass.getOrderClassState());
            orderClassListResponseVO.setOrderClassStateName("已发布");
            orderClassListResponseVO.setOrderClassRealityNumber(orderClass.getOrderClassRealityNumber());
            String startTime = timeUtils.setDateToStrDate(orderClass.getOrderClassStartTime(), Const.YYYY_MM_DD);
            orderClassListResponseVO.setOrderClassStartTime(startTime);
            String EndTime = timeUtils.setDateToStrDate(orderClass.getOrderClassEndTime(), Const.YYYY_MM_DD);
            orderClassListResponseVO.setOrderClassEndTime(EndTime);
            orderClassListResponseVO.setOrderClassAdministratorNo(orderClassAdminNo);
            OrderClassAdmin orderClassAdmin = orderClassAdminMapper.selectById(orderClassAdminNo);
            if (orderClassAdmin == null) {
                orderClassListResponseVO.setOrderClassAdministratorName("未填写");
            } else {
                orderClassListResponseVO.setOrderClassAdministratorName(orderClassAdmin.getOrderClassAdminName());
            }
            orderClassListResponseVO.setOrderClassBusinessNo(orderClass.getOrderClassBusinessNo());
            Business business = businessMapper.selectById(orderClass.getOrderClassBusinessNo());
            if (business == null) {
                orderClassListResponseVO.setOrderClassBusinessName("未填写");
                orderClassListResponseVO.setOrderClassBusinessOrderClassHeadName("未填写");
            } else {
                orderClassListResponseVO.setOrderClassBusinessName(business.getBusinessName());
                orderClassListResponseVO.setOrderClassBusinessOrderClassHeadName(business.getBusinessOrderClassHeadName());
                orderClassListResponseVO.setOrderClassBusinessRoomNo(business.getBusinessRoomNo());
                Room room = roomMapper.selectById(business.getBusinessRoomNo());
                if (room == null) {
                    orderClassListResponseVO.setOrderClassBusinessRoomNo("未填写");
                    orderClassListResponseVO.setOrderClassBusinessRoomName("未填写");
                } else {
                    orderClassListResponseVO.setOrderClassBusinessRoomNo(room.getRoomNo());
                    orderClassListResponseVO.setOrderClassBusinessRoomName(room.getRoomName());
                }
            }
            orderClassListResponseVO.setOrderClassMajorNo(orderClass.getOrderClassMajorNo());
            Major major = majorMapper.selectById(orderClass.getOrderClassMajorNo());
            if (major == null) {
                orderClassListResponseVO.setOrderClassMajorName("未填写");
            } else {
                orderClassListResponseVO.setOrderClassMajorName(major.getMajorName());
            }
            orderClassListResponseVO.setOrderClassCreateMan(orderClass.getOrderClassCreateMan());
            String createTime = timeUtils.setDateToStrDate(orderClass.getOrderClassCreateTime(), Const.YYYY_MM_DD);
            orderClassListResponseVO.setOrderClassCreateTime(createTime);
            if (orderClass.getOrderClassCreateMan() == null) {
                orderClassListResponseVO.setOrderClassUpdateMan("未更新");
            } else {
                orderClassListResponseVO.setOrderClassUpdateMan(orderClass.getOrderClassCreateMan());
            }
            if (orderClass.getOrderClassUpdateTime() == null) {
                orderClassListResponseVO.setOrderClassUpdateTime(null);
            } else {
                String updateTime = timeUtils.setDateToStrDate(orderClass.getOrderClassUpdateTime(), Const.YYYY_MM_DD);
                orderClassListResponseVO.setOrderClassUpdateTime(updateTime);
            }
            orderClassListResponseVO.setOrderClassCountNumber(orderClassCountNumber);
            orderClassListResponseVOList.add(orderClassListResponseVO);
        }
        return PageInfo.of(orderClassListResponseVOList);
    }

    /**
     * 根据班名、订单班管理员工号查询订单班信息（开班）
     *
     * @param pageNum           当前页
     * @param pageSize          当前页数据个数
     * @param orderClassAdminNo 订单班管理员工号
     * @param orderClassName    班名
     * @return 订单班信息
     */
    @Override
    public PageInfo<OrderClassListResponseVO> findOrderClassStartReleasePage(Integer pageNum, Integer pageSize, String orderClassAdminNo, String orderClassName) {
        PageHelper.startPage(pageNum, pageSize);
        LambdaQueryWrapper<OrderClass> orderClassLambdaQueryWrapper = new LambdaQueryWrapper<>();
        orderClassLambdaQueryWrapper
                .eq(OrderClass::getOrderClassAdministratorNo, orderClassAdminNo)
                .eq(OrderClass::getOrderClassState, 2)
                .like(OrderClass::getOrderClassName, orderClassName)
                .orderByDesc(OrderClass::getOrderClassCreateTime);
        List<OrderClass> orderClassList = orderClassMapper.selectList(orderClassLambdaQueryWrapper);
        List<OrderClassListResponseVO> orderClassListResponseVOList = new ArrayList<>();
        QueryWrapper<OrderClass> orderClassQueryWrapper = new QueryWrapper<>();
        orderClassQueryWrapper
                .eq("order_class_administrator_no", orderClassAdminNo)
                .eq("order_class_state", 2)
                .like("order_class_name", orderClassName);
        Long orderClassCountNumber = orderClassMapper.selectCount(orderClassQueryWrapper);
        for (OrderClass orderClass : orderClassList) {
            OrderClassListResponseVO orderClassListResponseVO = new OrderClassListResponseVO();
            orderClassListResponseVO.setOrderClassNo(orderClass.getOrderClassNo());
            orderClassListResponseVO.setOrderClassName(orderClass.getOrderClassName());
            orderClassListResponseVO.setOrderClassIntroduction(orderClass.getOrderClassIntroduction());
            orderClassListResponseVO.setOrderClassState(orderClass.getOrderClassState());
            orderClassListResponseVO.setOrderClassStateName("已开班");
            orderClassListResponseVO.setOrderClassRealityNumber(orderClass.getOrderClassRealityNumber());
            String startTime = timeUtils.setDateToStrDate(orderClass.getOrderClassStartTime(), Const.YYYY_MM_DD);
            orderClassListResponseVO.setOrderClassStartTime(startTime);
            String EndTime = timeUtils.setDateToStrDate(orderClass.getOrderClassEndTime(), Const.YYYY_MM_DD);
            orderClassListResponseVO.setOrderClassEndTime(EndTime);
            orderClassListResponseVO.setOrderClassAdministratorNo(orderClassAdminNo);
            OrderClassAdmin orderClassAdmin = orderClassAdminMapper.selectById(orderClassAdminNo);
            if (orderClassAdmin == null) {
                orderClassListResponseVO.setOrderClassAdministratorName("未填写");
            } else {
                orderClassListResponseVO.setOrderClassAdministratorName(orderClassAdmin.getOrderClassAdminName());
            }
            orderClassListResponseVO.setOrderClassBusinessNo(orderClass.getOrderClassBusinessNo());
            Business business = businessMapper.selectById(orderClass.getOrderClassBusinessNo());
            if (business == null) {
                orderClassListResponseVO.setOrderClassBusinessName("未填写");
                orderClassListResponseVO.setOrderClassBusinessOrderClassHeadName("未填写");
            } else {
                orderClassListResponseVO.setOrderClassBusinessName(business.getBusinessName());
                orderClassListResponseVO.setOrderClassBusinessOrderClassHeadName(business.getBusinessOrderClassHeadName());
                orderClassListResponseVO.setOrderClassBusinessRoomNo(business.getBusinessRoomNo());
                Room room = roomMapper.selectById(business.getBusinessRoomNo());
                if (room == null) {
                    orderClassListResponseVO.setOrderClassBusinessRoomNo("未填写");
                    orderClassListResponseVO.setOrderClassBusinessRoomName("未填写");
                } else {
                    orderClassListResponseVO.setOrderClassBusinessRoomNo(room.getRoomNo());
                    orderClassListResponseVO.setOrderClassBusinessRoomName(room.getRoomName());
                }
            }
            orderClassListResponseVO.setOrderClassMajorNo(orderClass.getOrderClassMajorNo());
            Major major = majorMapper.selectById(orderClass.getOrderClassMajorNo());
            if (major == null) {
                orderClassListResponseVO.setOrderClassMajorName("未填写");
            } else {
                orderClassListResponseVO.setOrderClassMajorName(major.getMajorName());
            }
            orderClassListResponseVO.setOrderClassCreateMan(orderClass.getOrderClassCreateMan());
            String createTime = timeUtils.setDateToStrDate(orderClass.getOrderClassCreateTime(), Const.YYYY_MM_DD);
            orderClassListResponseVO.setOrderClassCreateTime(createTime);
            if (orderClass.getOrderClassCreateMan() == null) {
                orderClassListResponseVO.setOrderClassUpdateMan("未更新");
            } else {
                orderClassListResponseVO.setOrderClassUpdateMan(orderClass.getOrderClassCreateMan());
            }
            if (orderClass.getOrderClassUpdateTime() == null) {
                orderClassListResponseVO.setOrderClassUpdateTime(null);
            } else {
                String updateTime = timeUtils.setDateToStrDate(orderClass.getOrderClassUpdateTime(), Const.YYYY_MM_DD);
                orderClassListResponseVO.setOrderClassUpdateTime(updateTime);
            }
            orderClassListResponseVO.setOrderClassCountNumber(orderClassCountNumber);
            orderClassListResponseVOList.add(orderClassListResponseVO);
        }
        return PageInfo.of(orderClassListResponseVOList);
    }

    /**
     * 根据班名、订单班管理员工号查询订单班信息（所有）
     *
     * @param pageNum           当前页
     * @param pageSize          当前页数据个数
     * @param orderClassAdminNo 订单班管理员工号
     * @param orderClassName    班名
     * @return 订单班信息
     */
    @Override
    public PageInfo<OrderClassListResponseVO> findOrderClassPage(Integer pageNum, Integer pageSize, String orderClassAdminNo, String orderClassName) {
        PageHelper.startPage(pageNum, pageSize);
        LambdaQueryWrapper<OrderClass> orderClassLambdaQueryWrapper = new LambdaQueryWrapper<>();
        orderClassLambdaQueryWrapper
                .eq(OrderClass::getOrderClassAdministratorNo, orderClassAdminNo)
                .like(OrderClass::getOrderClassName, orderClassName)
                .orderByDesc(OrderClass::getOrderClassCreateTime);
        List<OrderClass> orderClassList = orderClassMapper.selectList(orderClassLambdaQueryWrapper);
        List<OrderClassListResponseVO> orderClassListResponseVOList = new ArrayList<>();
        QueryWrapper<OrderClass> orderClassQueryWrapper = new QueryWrapper<>();
        orderClassQueryWrapper
                .eq("order_class_administrator_no", orderClassAdminNo)
                .like("order_class_name", orderClassName);
        Long orderClassCountNumber = orderClassMapper.selectCount(orderClassQueryWrapper);
        for (OrderClass orderClass : orderClassList) {
            OrderClassListResponseVO orderClassListResponseVO = new OrderClassListResponseVO();
            orderClassListResponseVO.setOrderClassNo(orderClass.getOrderClassNo());
            orderClassListResponseVO.setOrderClassName(orderClass.getOrderClassName());
            orderClassListResponseVO.setOrderClassIntroduction(orderClass.getOrderClassIntroduction());
            if (0 == orderClass.getOrderClassState()) {
                orderClassListResponseVO.setOrderClassState(orderClass.getOrderClassState());
                orderClassListResponseVO.setOrderClassStateName("未发布");
            } else if (1 == orderClass.getOrderClassState()) {
                orderClassListResponseVO.setOrderClassState(orderClass.getOrderClassState());
                orderClassListResponseVO.setOrderClassStateName("未开班");
            } else if (2 == orderClass.getOrderClassState()) {
                orderClassListResponseVO.setOrderClassState(orderClass.getOrderClassState());
                orderClassListResponseVO.setOrderClassStateName("已开班");
            } else {
                orderClassListResponseVO.setOrderClassState(orderClass.getOrderClassState());
                orderClassListResponseVO.setOrderClassStateName("已结班");
            }
            orderClassListResponseVO.setOrderClassRealityNumber(orderClass.getOrderClassRealityNumber());
            String startTime = timeUtils.setDateToStrDate(orderClass.getOrderClassStartTime(), Const.YYYY_MM_DD);
            orderClassListResponseVO.setOrderClassStartTime(startTime);
            String EndTime = timeUtils.setDateToStrDate(orderClass.getOrderClassEndTime(), Const.YYYY_MM_DD);
            orderClassListResponseVO.setOrderClassEndTime(EndTime);
            orderClassListResponseVO.setOrderClassAdministratorNo(orderClassAdminNo);
            OrderClassAdmin orderClassAdmin = orderClassAdminMapper.selectById(orderClassAdminNo);
            if (orderClassAdmin == null) {
                orderClassListResponseVO.setOrderClassAdministratorName("未填写");
            } else {
                orderClassListResponseVO.setOrderClassAdministratorName(orderClassAdmin.getOrderClassAdminName());
            }
            orderClassListResponseVO.setOrderClassBusinessNo(orderClass.getOrderClassBusinessNo());
            Business business = businessMapper.selectById(orderClass.getOrderClassBusinessNo());
            if (business == null) {
                orderClassListResponseVO.setOrderClassBusinessName("未填写");
                orderClassListResponseVO.setOrderClassBusinessOrderClassHeadName("未填写");
            } else {
                orderClassListResponseVO.setOrderClassBusinessName(business.getBusinessName());
                orderClassListResponseVO.setOrderClassBusinessOrderClassHeadName(business.getBusinessOrderClassHeadName());
                orderClassListResponseVO.setOrderClassBusinessRoomNo(business.getBusinessRoomNo());
                Room room = roomMapper.selectById(business.getBusinessRoomNo());
                if (room == null) {
                    orderClassListResponseVO.setOrderClassBusinessRoomNo("未填写");
                    orderClassListResponseVO.setOrderClassBusinessRoomName("未填写");
                } else {
                    orderClassListResponseVO.setOrderClassBusinessRoomNo(room.getRoomNo());
                    orderClassListResponseVO.setOrderClassBusinessRoomName(room.getRoomName());
                }
            }
            orderClassListResponseVO.setOrderClassMajorNo(orderClass.getOrderClassMajorNo());
            Major major = majorMapper.selectById(orderClass.getOrderClassMajorNo());
            if (major == null) {
                orderClassListResponseVO.setOrderClassMajorName("未填写");
            } else {
                orderClassListResponseVO.setOrderClassMajorName(major.getMajorName());
            }
            orderClassListResponseVO.setOrderClassCreateMan(orderClass.getOrderClassCreateMan());
            String createTime = timeUtils.setDateToStrDate(orderClass.getOrderClassCreateTime(), Const.YYYY_MM_DD);
            orderClassListResponseVO.setOrderClassCreateTime(createTime);
            if (orderClass.getOrderClassCreateMan() == null) {
                orderClassListResponseVO.setOrderClassUpdateMan("未更新");
            } else {
                orderClassListResponseVO.setOrderClassUpdateMan(orderClass.getOrderClassCreateMan());
            }
            if (orderClass.getOrderClassUpdateTime() == null) {
                orderClassListResponseVO.setOrderClassUpdateTime(null);
            } else {
                String updateTime = timeUtils.setDateToStrDate(orderClass.getOrderClassUpdateTime(), Const.YYYY_MM_DD);
                orderClassListResponseVO.setOrderClassUpdateTime(updateTime);
            }
            orderClassListResponseVO.setOrderClassCountNumber(orderClassCountNumber);
            orderClassListResponseVOList.add(orderClassListResponseVO);
        }
        return PageInfo.of(orderClassListResponseVOList);
    }
}
